<template>
	<view class="contents">
		<view class="refundgoods">
			退款商品
		</view>
		<!-- <view style="height: 80rpx;"></view> -->
		<view class="oredr_list" v-for="item,index in orderFrom" :key="index">
			<view class="order_head">
				<view class="order">
					订单编号：{{item.order_id}}
				</view>

			</view>
			<view class="order_content" v-for="i in item.cartInfo" :key="i.id">
				<view class="order_img">
					<image :src="i.productInfo.image" mode=""></image>
				</view>
				<view class="order_text">
					<view class="order_title">
						{{i.productInfo.store_name}}
					</view>
					<view class="order_detail">
						{{i.is_spec==0?i.productInfo.store_info:i.spec.sku}}
					</view>
					<view class="order_tab">
						<view class="tab_list" v-for="(item,index) in 1" :key="index">
							五折
						</view>
					</view>
					<view class="order_price">
						<view class="spellgroup">
							<view class="new_price">
								￥{{i.productInfo.price}}
							</view>
							<!-- <view class="tab_list" v-for="(item,index) in 1" :key="index">
								2人团
							</view> -->
						</view>

						<view class="old_price">
							￥{{i.productInfo.ot_price}}
						</view>
					</view>

				</view>
			</view>
		</view>
		<view class="neirong">
			<view class="from">
				<view class="list">
					<view class="left">
						申请类型
					</view>
					<view class="center" @click="chooseType">
						<text>{{refundDetails.type}}</text>
					</view>
					<view class="right" @click="chooseType">
						<image src="http://one-huoke.oss-cn-hangzhou.aliyuncs.com/27270202209221534514540.png" mode="">
						</image>
					</view>
				</view>
				<view class="list">
					<view class="left">
						退款原因
					</view>
					<view class="center" @click="chooseReason">
						<text>{{refundDetails.reason}}</text>
					</view>
					<view class="right" style="color: #999999;" @click="chooseReason">
						<image src="http://one-huoke.oss-cn-hangzhou.aliyuncs.com/27270202209221534514540.png"></image>
						<text v-if="!refundDetails.reason">请选择</text>
					</view>
				</view>
				<view class="list">
					<view class="left">
						退款金额
					</view>
					<view class="right">
						￥{{orderFrom[0].total_price}}
					</view>
				</view>
				<view class="list">
					<view class="left">
						上传凭证
					</view>
					<view class="right">
						{{picList.length}}/3
					</view>
				</view>
				<view class="uploaddocuments" >
					<view class="left" @click="uploadDocuments">
						<image src="../../static/camera.svg" mode="widthFix" ></image>
					</view>
					<view class="right" v-for="(item,index) in picList" :key="index">
						<image :src="item"></image>
						<view class="right_top" @click="deleteImage(index)">
							<image src="https://www.szzn.group/uploads/20221126/92e7c8bc19b22e04464bb6a23c792c6d.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<bottom-confirm @click.native='gotoReturnDetails'></bottom-confirm>
	</view>
</template>

<script>
	import {orderDetail,submitShopingRefund} from '@/api/api.js'
	export default {
		data() {
			return {
				active: 0,
				orderFrom:[],
				orderList:[],
				refundDetails: {
					type: '',
					reason: '',
					amount: 23
				},
				picList: [],
				newimg: {
					src:''
				},
				img_num:0,
				orderId:'',
				from:{
					is_edit:0,
					uni:'',
					remarks:'',
					refund_reason:'',
					type:'',
					pic:[]
				}
			}
		},
		onLoad(options) {
			console.log(options.order_id)
			this.orderId = options.orderId
			this.from.uni = this.orderId
			this.init()
		},
		methods: {
			init() {
				let data = `uni=${this.orderId}`
				orderDetail(data).then(res => {
					console.log(res)
					this.orderFrom = res.data.data.order
					this.orderList = res.data.data.order.cartInfo
					this.payTime = this.orderFrom[0].add_time
					let time = new Date(this.payTime * 1000)
					let y = time.getFullYear()
					let m = time.getMonth() + 1
					let d = time.getDate()
					let h = time.getHours()
					let f = time.getMinutes()
					let s = time.getSeconds()
					console.log(y, m, d, h, f, s)
					if (m < 10) {
						m = '0' + m
					}
					if (f < 10) {
						f = '0' + f
					}
					if (s < 10) {
						s = '0' + s
					}
					this.payTime = y + '-' + m + '-' + d + ' ' + h + ':' + f + ':' + s
			
			
					if (this.orderFrom[0].paid == 0) {
						this.order = false
					} else {
						this.order = true
					}
				})
			},
			onChange(e) {
				this.active = e.detail.index
				console.log(e.detail.index)
			},
			// 选择类型
			chooseType() {
				let that = this;
				uni.showActionSheet({
					title: '请选择申请类型',
					itemList: ['我要退货退款', '我要退款(无需退货)'],
					success: function(res) {
						// console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						if (res.tapIndex == 0) {
							that.refundDetails.type = '我要退货退款'
						} else{
							that.refundDetails.type = '我要退款(无需退货)'
						}
						that.from.type = res.tapIndex + 1
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			// 选择退款原因
			chooseReason() {
				let that = this
				uni.showActionSheet({
					title: '退款原因',
					itemList: ['描述与商品不符', '不想要了', '地址填错', '多拍,错拍', '未发货'],
					success: function(res) {
						// console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						if (res.tapIndex == 0) {
							that.refundDetails.reason = '描述与商品不符'
						} else if (res.tapIndex == 1) {
							that.refundDetails.reason = '不想要了'
						} else if (res.tapIndex == 2) {
							that.refundDetails.reason = '地址填错'
						} else if (res.tapIndex == 3) {
							that.refundDetails.reason = '多拍,错拍'
						} else if (res.tapIndex == 4) {
							that.refundDetails.reason = '未发货'
						}
						that.from.refund_reason = that.refundDetails.reason

					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			// 上传凭证
			uploadDocuments() {
				let that = this
				if(this.picList.length<3) {
					uni.chooseImage({
					success: function(res) {
						console.log(res.tempFilePaths[0])
						that.newimg.src = res.tempFilePaths[0]
						console.log(that.newimg)
						that.picList.push(that.newimg.src)
						that.from.pic = that.picList
						console.log(that.picList)
					}
				});
				}
			},
			// 删除凭证
			deleteImage(e) {
				console.log(e)
				this.picList.splice(e,1)
				console.log(this.picList.length)
			},
			// 返回退款详情
			gotoReturnDetails() {
				
				if(this.from.refund_reason == '')return uni.showToast({
					title:'请选择退款原因'
				})
				if(this.from.type == '')return uni.showToast({
					title:'请选择退款类型'
				})
				if(this.from.pic.length == 0)return uni.showToast({
					title:'请上传凭证'
				})
				this.from.pic  = JSON.stringify(this.from.pic)
				submitShopingRefund(this.from).then(res=>{
					if(res.data.code == '200'){
						uni.showToast({
							title:'提交成功',
							duration:2000
						})
						let time = setTimeout(()=>{
							uni.navigateTo({
								url: '/myIndex/returnDetails/returnDetails?orderId='+this.orderId
							})
						},500)
						
					}else {
						uni.showToast({
							title:res.data.msg
						})
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">
	.contents {
		width: 100%;
		min-height: 100vh;
		background-color: rgb(247, 249, 252);

		.refundgoods {
			height: 80rpx;
			line-height: 80rpx;
			width: 694rpx;
			box-sizing: border-box;
			margin: 0 auto;
			padding: 0 28rpx;
		}

		.oredr_list {
			width: 694rpx;
			// height: 456rpx;
			background-color: #fff;
			border-radius: 10rpx;
			margin: 0 auto;
			padding-bottom: 40rpx;

			.order_head {
				box-sizing: border-box;
				padding: 0 28rpx;
				width: 100%;
				height: 80rpx;
				line-height: 80rpx;
				display: flex;
				justify-content: space-between;
				font-size: 26rpx;

				.order {
					color: #999999;
				}

				.status {
					color: #D41312;
				}
			}

			.order_content {
				box-sizing: border-box;
				padding: 0 28rpx;
				width: 100%;
				height: 182rpx;
				display: flex;

				.order_img {
					width: 182rpx;
					height: 182rpx;
					flex-shrink: 0;

					image {
						border-radius: 8rpx;
						width: 100%;
						height: 100%;
					}
				}

				.order_text {
					margin-left: 30rpx;
					width: 470rpx;

					.order_title {
						width: 100%;
						height: 40rpx;
						line-height: 40rpx;
						font-size: 30rpx;
						color: #333;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						-o-text-overflow: ellipsis;
					}

					.order_detail {
						margin-top: 10rpx;
						width: 470rpx;
						height: 40rpx;
						line-height: 40rpx;
						font-size: 26rpx;
						color: #999999;
						text-overflow: ellipsis;
						white-space: nowrap;
						overflow: hidden;
					}

					.order_tab {
						margin-top: 15rpx;
						width: 100%;
						height: 30rpx;
						line-height: 30rpx;
						font-size: 26rpx;
						display: flex;

						.tab_list {
							width: 56rpx;
							height: 32rpx;
							background-color: rgb(255, 234, 234);
							color: rgb(255, 45, 45);
							font-size: 20rpx;
							text-align: center;
							line-height: 32rpx;
							margin-right: 20rpx;
							border-radius: 6rpx;
						}
					}

					.order_price {
						margin-top: 10rpx;
						width: 100%;
						height: 30rpx;
						line-height: 30rpx;
						font-size: 26rpx;

						.spellgroup {
							display: flex;

							.new_price {
								color: #3DB963;
								font-size: 24rpx;
								margin-right: 20rpx;
							}

							.tab_list {
								// width: 56rpx;
								height: 32rpx;
								background-color: rgb(61, 185, 99);
								color: rgb(255, 255, 255);
								font-size: 20rpx;
								text-align: center;
								line-height: 32rpx;
								padding: 0 12rpx;
								border-radius: 6rpx;
							}
						}

						.old_price {
							color: #999999;
							font-size: 22rpx;
							text-decoration: line-through;
							margin-left: 6rpx;
						}

					}
				}
			}

			.fengexian {
				width: 640rpx;
				border: 1rpx solid #EEEEEE;
				margin: 30rpx auto 0;
			}

			.order_time {
				box-sizing: border-box;
				padding: 0 28rpx;
				width: 100%;
				height: 30rpx;
				line-height: 30rpx;
				display: flex;
				justify-content: space-between;
				font-size: 26rpx;
				margin-top: 20rpx;
				color: #999999;
				font-size: 26rpx;

				span {
					color: #3DB963;
				}
			}

			.order_bottom {
				width: 100%;
				display: flex;
				margin-top: 25rpx;

			}

		}

		.neirong {
			width: 694rpx;
			height: 584rpx;
			background-color: #fff;
			overflow: hidden;
			border-radius: 10rpx;
			margin: 30rpx auto;

			.from {
				width: 664rpx;
				height: 584rpx;
				margin: 0 20rpx 20rpx 20rpx;

				.list {
					width: 100%;
					height: 98rpx;
					border-top: 1rpx solid rgb(244, 244, 244);
					display: flex;
					justify-content: space-between;
					align-items: center;

					.left {
						width: 120rpx;
						height: 97rpx;
						line-height: 97rpx;
						font-size: 26rpx;
						font-weight: 600;
						text-align: center;
					}

					.center {
						flex: 1;
						padding-left: 36rpx;
						height: 97rpx;
						line-height: 97rpx;
						font-size: 26rpx;
						font-weight: 600;

					}

					.right {
						width: 130rpx;
						height: 97rpx;
						line-height: 97rpx;
						// margin-left: 80rpx;
						// padding-right: 24rpx;
						font-size: 26rpx;
						font-weight: 600;
						display: flex;
						align-items: center;
						flex-direction: row-reverse;
						margin-right: 18rpx;

						image {
							display: block !important;
							width: 35rpx !important;
							height: 35rpx !important;
							// border-radius: 50%;
							// margin-top: 16rpx;
							// margin-left: 380rpx;
						}

						input {
							width: 450rpx;
							height: 77rpx;
							margin-top: 10rpx;
							text-align: right;
							text-overflow: ellipsis;
							overflow: hidden;
							white-space: normal;
						}
					}
				}

				.lists {
					width: 684rpx;
					height: 98rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.left {
						width: 100rpx;
						height: 97rpx;
						line-height: 97rpx;
						font-size: 26rpx;
						font-weight: 600;
						text-align: center;
					}

					.right {
						width: 500rpx;
						height: 97rpx;
						margin-left: 80rpx;

						image {
							display: block;
							height: 100%;
							// width: 35rpx;
							// height: 35rpx;
							// margin-top: 16rpx;
							// margin-left: 380rpx;
						}

						input {
							width: 450rpx;
							height: 77rpx;
							margin-top: 10rpx;
							text-align: right;
							text-overflow: ellipsis;
							overflow: hidden;
							white-space: normal;
						}
					}
				}

				.uploaddocuments {
					display: flex;
					align-items: center;
					.left {
						height: 120rpx;
						width: 120rpx;
						border: 2rpx dotted #999999;
						display: flex;
						justify-content: center;
						align-items: center;
						image {
							width: 40%;
						}
					}
					.right {
						height: 120rpx;
						width: 120rpx;
						border: 2rpx solid #999999;
						margin: 0 16rpx;
						position: relative;
						image {
							width: 100%;
							height: 100%;
						}
						.right_top {
							width: 32rpx;
							height: 32rpx;
							border-radius: 16rpx;
							position: absolute;
							top: -16rpx;
							right: -16rpx;
							image {
								width: 35rpx;
								height: 35rpx;
							}
						} 
					}

				}
			}

		}
	}
</style>
